#version 450 core

layout(location = 0) in vec3 normal;
layout(location = 1) in vec3 fragPos;
layout(location = 0) out vec4 fragColor;

struct World {
    vec3 cameraPos;
    mat4 matVP;
};
layout(binding = 0, std140) uniform WorldBlock {
    World world;
};

struct Transform {
    mat4 modelMatrix; // 2
    mat4 mvpMatrix; // 3
    mat4 normalMatrix; // 4
};
layout(location = 2) uniform Transform transform;

struct Material {
    vec3 color; // 5
    float shiness; // 6
};
layout(location = 5) uniform Material material;

struct Light {
    vec3 ambient; // 7
    vec3 diffuse; // 8
    vec3 specular; // 9
    vec3 position; // 10
};
layout(location = 7) uniform Light light;

void main() {
    vec3 ambient = light.ambient * material.color;
    vec3 lightDir = normalize(light.position - fragPos);
    vec3 diffuse = max(dot(lightDir, normal), 0.0f) * light.diffuse;
    vec3 reflectDir = reflect(-lightDir, normal);
    vec3 viewDir = normalize(world.cameraPos - fragPos);
    float spec = pow(max(dot(viewDir, reflectDir), 0.0f), material.shiness);
    vec3 specular = spec * light.specular * material.color;
    vec3 result = ambient + diffuse + specular;
    fragColor = vec4(result, 1.0f);
}
